package com.youhome.business.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.common.response.ResultPage;
import com.youhome.service.service.BShareLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2017/11/6.
 */
@RestController
@RequestMapping(value = "/sharelog")
@Api(tags = "分享日志")
public class ShareLogController {

    @Autowired
    private BShareLogService bShareLogService;

    @ApiOperation(value = "分享日志列表", notes = "根据分享组UUID获取分享日志列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "int", name = "pageNumber", value = "页码", paramType = "query"),
            @ApiImplicitParam(dataType = "int", name = "pageSize", value = "每页条数", paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "shareId", value = "分享组ID", required = true, paramType = "query")
    })
    @GetMapping(value = "/list")
    public Object list(Integer pageNumber, Integer pageSize, String shareId) throws CustomException {
        return new ResultPage(ResultCode.SUCCESS, bShareLogService.selectByShareId(pageNumber, pageSize, shareId));
    }

    @ApiOperation(value = "分享组最近30访问日志列表", notes = "根据分享组UUID获取分享组最近30访问日志列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "shareId", value = "分享组ID", required = true, paramType = "query")
    })
    @GetMapping(value = "/last30day")
    public Object last30day(String shareId) throws CustomException {
        return new Result(ResultCode.SUCCESS, bShareLogService.selectLast30DayDateItemByShareId(shareId));
    }


}
